package com.smh.a02exerciseDemo1;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.TreeMap;

public class Test2 {
    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new FileReader("day27-code\\file\\csb.txt"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("day27-code\\file\\d.txt"));
        //treeMap
        String s;
        TreeMap<Integer, String> tm = new TreeMap<>();
        //ArrayList
        ArrayList<String> list = new ArrayList<>();

        while ((s = br.readLine()) != null) {
            int index = Integer.valueOf(s.charAt(0) + "");
            tm.put(index, s.substring(2, s.length()));
            list.add(s);
        }

        System.out.println(tm);

        tm.forEach((integer, s1) -> {
            try {
                bw.write(s1);
                bw.newLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
        Collections.sort(list, ((o1, o2) -> {
            return Integer.parseInt(o1.substring(0, 1)) - Integer.parseInt(o2.substring(0, 1));
        }));

        System.out.println(list);

        bw.close();
        br.close();


    }
}
